package com.wwg.market.ui.code.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Widget;
import com.mobileares.midp.mui.client.form.UFishFlowForm;
import com.mobileares.midp.widgets.client.button.CButton;
import com.mobileares.midp.widgets.client.pop.PopPanel;
import com.mobileares.midp.widgets.client.textbox2.*;
import com.nexustar.gwt.widgets.client.asyn.LoadingAsyncCallback;
import com.wwfish.gwt.model.client.IModelCallback;
import com.wwfish.gwt.model.client.ISaveAndUpdateModelProvider;
import com.wwfish.gwt.model.client.impl.FishModelManager;
import com.wwfish.gwt.model.client.impl.FormModel;
import com.wwfish.gwt.model.client.impl.ListModel;
import com.wwg.market.ui.dashboard.client.Utils;
import com.wwg.market.ui.service.dto.GeneralCodeDto;
import com.wwg.market.ui.service.interfaces.CodeService;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author gaoyang
 * @version $Id: $
 * @date 11-12-20 上午12:56
 */
public class ViewCodeForm {
    private UFishFlowForm<GeneralCodeDto> form;
    private PopPanel pop;

    public ViewCodeForm() {
        pop = new PopPanel(true);
        init();
        initFormModel();
    }

    private void init() {
        form = new UFishFlowForm<GeneralCodeDto>(1);
        TextBoxLabel text = new TextBoxLabel("代码名称:");
        TextBoxLabel code = new TextBoxLabel("代码值:");
        TextAreaLabel description = new TextAreaLabel("描述:");

        text.getLabelWidget().setReadOnly(true);
        code.getLabelWidget().setReadOnly(true);
        description.getLabelWidget().setReadOnly(true);


        form.addElement(text, "name");
        form.addElement(code, "code");
        form.addElement(description, "description");
        pop.addBodyWidget(form);


        CButton close = new CButton("关闭");
        close.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent clickEvent) {
                hidden();
            }
        });

        pop.addFootButton(close);
    }

    public void show(GeneralCodeDto dto) {
        form.getFishModel().load(dto);
        pop.show();
    }

    public void hidden() {
        pop.hidden();
    }

    public void setTitle(String text) {
        pop.setHeadText(text);
    }


    private void initFormModel() {
        FormModel model = (FormModel) FishModelManager.createTempModel(FishModelManager.TYPE_FORM);
        form.setFishModel(model);
    }

}
